package com.silverbox.sweeporder.common.util;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.silverbox.sweeporder.common.AlipayServiceEnvConstants;


/**
 * API调用客户端工厂
 * 
 */
public class AlipayAPIClientFactory { 
	
    /** API调用客户端 */
    private static AlipayClient alipayClient;
    
    /** API调用客户端 */
    private static AlipayClient payAlipayClient;
    
    /**
     * 获得API调用客户端
     * @return
     */
    public static AlipayClient getAlipayClient(){
        
        if(null == alipayClient){
            alipayClient = new DefaultAlipayClient(AlipayServiceEnvConstants.ALIPAY_GATEWAY.getValue(), AlipayServiceEnvConstants.APP_ID.getValue(), 
                AlipayServiceEnvConstants.PRIVATE_KEY.getValue(), "json", AlipayServiceEnvConstants.CHARSET.getValue(),AlipayServiceEnvConstants.ALIPAY_PUBLIC_KEY.getValue());
        }
        return alipayClient;
    }
    
    /**
     * 获得API调用客户端
     * @param gateway     支付宝网关
     * @param appid		    支付宝签约appid
     * @param privateKey  RSA私钥
     * @param publicKey   支付宝公钥
     * @return
     */
    public static AlipayClient getAlipayClient(String gateway,String appid,String privateKey,String publicKey){
    	payAlipayClient = new DefaultAlipayClient(gateway, appid,privateKey, "json", AlipayServiceEnvConstants.CHARSET.getValue(),publicKey);
       return payAlipayClient;
    }
    
    /**
     * 获得支付宝小程序API调用客户端
     * @param gateway     支付宝网关
     * @param appid		    支付宝签约appid
     * @param privateKey  RSA私钥
     * @param publicKey   支付宝公钥
     * @return
     */
    public static AlipayClient getAlipayClientSmallProgram(){
        if(null == alipayClient){
            alipayClient = new DefaultAlipayClient(AlipayServiceEnvConstants.ALIPAY_GATEWAY.getValue(), AlipayServiceEnvConstants.SMALL_PROGRAM_APP_ID.getValue(), 
                AlipayServiceEnvConstants.SMALL_PROGRAM_PRIVATE_KEY.getValue(), "json", AlipayServiceEnvConstants.SMALL_PROGRAM_CHARSET.getValue(),AlipayServiceEnvConstants.SMALL_PROGRAM_PUBLIC_KEY.getValue(),AlipayServiceEnvConstants.SMALL_PROGRAM_SIGN_TYPE.getValue());
        }
        return alipayClient;
    }
}
